package com.gitee.wsl.compose.ui.section.lazylist.item

import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.runtime.Composable
import androidx.compose.ui.unit.Dp
import com.gitee.wsl.compose.ui.section.CupertinoSectionDefaults
import com.gitee.wsl.compose.ui.section.LabelCaption
import com.gitee.wsl.compose.ui.section.lazylist.LazySectionScope

/**
 * Clickable label with trailing icon (chevron by default), [title], optional [icon] and [caption].
 *
 * @param onClick action performed on label click.
 * @param key optional key for item.
 * @param enabled if label is clickable.
 * @param icon icon displayed at the start of this item. [CupertinoLinkIcon] is often used for it.
 * @param dividerPadding start divider padding. By default inferred from presence of [icon].
 * @param onClickLabel semantics description of this label. Should be the same text as in [title].
 * @param interactionSource label interaction source.
 * @param caption content displayed before the label chevron.
 * @param title label title.
 *
 * @see CupertinoLinkIcon
 * @see switch
 * */
fun LazySectionScope.Link(
    onClick: () -> Unit,
    key: Any? = null,
    enabled: Boolean = true,
    icon: (@Composable () -> Unit)? = null,
    dividerPadding: Dp = if (icon != null)
        CupertinoSectionDefaults.DividerPaddingWithIcon
    else CupertinoSectionDefaults.DividerPadding,
    onClickLabel: String? = null,
    interactionSource: MutableInteractionSource? = null,
    caption : @Composable () -> Unit = {},
    trailingIcon : @Composable () -> Unit = {
        CupertinoSectionDefaults.LabelChevron()
    },
    title: @Composable () -> Unit,
) = LabelWithCustomChevron(
    chevron = {
        LabelCaption(caption)
        trailingIcon()
    },
    onClick = onClick,
    key = key,
    enabled = enabled,
    icon = icon,
    dividerPadding = dividerPadding,
    onClickLabel = onClickLabel,
    interactionSource = interactionSource,
    title = title,
)